package com.unitedvision.core.domain;

public class Customer implements GeneralType {
	private int id;
	private String name;
	private CustomerType type;
	private Address address;
	private Contact contact;
	
	public Customer() {
		super();
	}

	public Customer(String name, CustomerType type, Address address, Contact contact) {
		super();
		this.name = name;
		this.type = type;
		this.address = address;
		this.contact = contact;
	}

	public Customer(int id, String name, CustomerType type, Address address, Contact contact) {
		super();
		this.id = id;
		this.name = name;
		this.type = type;
		this.address = address;
		this.contact = contact;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public CustomerType getType() {
		return type;
	}

	public void setType(CustomerType type) {
		this.type = type;
	}

	public Address getAddress() {
		return address;
	}

	public void setAddress(Address address) {
		this.address = address;
	}
	
	public String getCity() {
		if (address == null)
			return "Data alamat belum dimasukkan";
		return address.getCity();
	}
	
	public void setCity(String city) {
		if (address == null)
			address = new Address();
		address.setCity(city);
	}

	public String getStreet() {
		if (address == null)
			return "Data alamat belum dimasukkan";
		return address.getStreet();
	}
	
	public void setStreet(String street) {
		if (address == null)
			address = new Address();
		address.setStreet(street);
	}

	public Contact getContact() {
		return contact;
	}

	public void setContact(Contact contact) {
		this.contact = contact;
	}

	public String getEmail() {
		if (contact == null)
			return "Data kontak belum dimasukkan";
		return contact.getEmail();
	}
	
	public void setEmail(String email) {
		if (contact == null)
			contact = new Contact();
		contact.setEmail(email);
	}
	
	public String getPhone() {
		if (contact == null)
			return "Data kontak belum dimasukkan";
		return contact.getPhone();
	}

	public void setPhone(String phone) {
		if (contact == null)
			contact = new Contact();
		contact.setPhone(phone);
	}
	
	@Override
	public String toString() {
		return "Customer [id=" + id + ", name=" + name + ", type=" + type
				+ ", address=" + address + ", contact=" + contact + "]";
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((address == null) ? 0 : address.hashCode());
		result = prime * result + ((contact == null) ? 0 : contact.hashCode());
		result = prime * result + id;
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		result = prime * result + ((type == null) ? 0 : type.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Customer other = (Customer) obj;
		if (address == null) {
			if (other.address != null)
				return false;
		} else if (!address.equals(other.address))
			return false;
		if (contact == null) {
			if (other.contact != null)
				return false;
		} else if (!contact.equals(other.contact))
			return false;
		if (id != other.id)
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		if (type == null) {
			if (other.type != null)
				return false;
		} else if (!type.equals(other.type))
			return false;
		return true;
	}
}
